home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / msqllib / example / speed_test / speed_test.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  3KB  |  125 lines

  1. /*
  2.         msql.library TCP/IP stack vs mUSD speed test
  3.         ©1998 Christophe Sollet (cfc@iname.com)
  4.  
  5. */
  6.  
  7. #include <exec/types.h>
  8. #include <proto/exec.h>
  9. #include <proto/msql.h>
  10. #include <stdio.h>
  11. #include <time.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14.  
  15. struct Library *MsqlBase;
  16.  
  17. void Test(struct MsqlConnection *);
  18.  
  19. main()
  20. {
  21.     struct MsqlConnection *co;
  22.  
  23.     if(MsqlBase = OpenLibrary("msql.library", 3))   /* Open the library */
  24.     {
  25.         /* Before doing any msql operation, we need a valid MsqlConnection structure */
  26.         if(co = MsqlAllocConnection())
  27.         {
  28.             /* Now we'll attempt a connection on a local mSQL database engine */
  29.             /* Using "localhost", we're connecting by the TCP/IP stack */
  30.             if(MsqlConnect(co, "localhost"))
  31.             {
  32.                 time_t stime = time(NULL), etime;
  33.                 double diff;
  34.                 Test(co);
  35.                 MsqlClose(co);
  36.                 etime = time(NULL);
  37.                 diff = difftime(etime, stime);
  38.                 printf("The test using TCP/IP stack took %.0f seconds\n", diff);
  39.                 
  40.             } else
  41.             {
  42.                 printf("Connection failed\n");
  43.                 printf("%s\n", MsqlGetErrMsg(co));
  44.             }
  45.  
  46.             /* Now we'll attempt a connection on a local mSQL database engine */
  47.             /* Using NULL, we're connecting by the mUSD */
  48.             if(MsqlConnect(co, NULL))
  49.             {
  50.                 time_t stime = time(NULL), etime;
  51.                 double diff;
  52.                 Test(co);
  53.                 MsqlClose(co);
  54.                 etime = time(NULL);
  55.                 diff = difftime(etime, stime);
  56.                 printf("The test using mUSD took %.0f seconds\n", diff);
  57.             } else
  58.             {
  59.                 printf("Connection failed\n");
  60.                 printf("%s\n", MsqlGetErrMsg(co));
  61.             }
  62.  
  63.  
  64.             MsqlFreeConnection(co);
  65.         } else printf("Alloc failed\n");
  66.         CloseLibrary(MsqlBase);
  67.     } else printf("Open Libs failed\n");
  68. }
  69.  
  70. void Test(struct MsqlConnection *co)
  71. {
  72.     m_result *mre, *mre2;
  73.     m_row    dbname, tablename;
  74.  
  75.     /* Gets current DB list */
  76.     mre = MsqlListDBs(co);
  77.     if(mre)
  78.     {
  79.         /* Get the name of the first db */
  80.         if(dbname = MsqlFetchRow(mre))
  81.         {
  82.             printf("%s", *dbname);
  83.  
  84.             /* Select this db */
  85.             if(MsqlSelectDB(co, *dbname) != -1)
  86.             {
  87.                 printf(" selected\n");
  88.                 if(mre2 = MsqlListTables(co))
  89.                 {
  90.                        /* Get the name of the first table */
  91.                     if(tablename = MsqlFetchRow(mre2))
  92.                     {
  93.                         int i;
  94.                         char *query;
  95.                         if(query = calloc(strlen(*tablename)+16, sizeof(char)))
  96.                         {
  97.                             sprintf(query, "SELECT * FROM %s", *tablename);
  98.                             printf("\t'%s' 100 times\n", query);
  99.                             for(i=0; i<100; i++)
  100.                             {
  101.                                 MsqlQuery(co, query);
  102.                                 printf(".");
  103.                                 fflush(stdout);
  104.                             }
  105.                             printf("\n");
  106.                             free(query);
  107.                         }
  108.                     }
  109.                 }
  110.                 MsqlFreeResult(mre2);
  111.             }
  112.             else
  113.             {
  114.                 printf("\nSelectDB failed\n");
  115.                 printf("%s\n", MsqlGetErrMsg(co)); // Display err message
  116.             }
  117.         }
  118.         MsqlFreeResult(mre);
  119.     } else
  120.     {
  121.         printf("ListDBs failed\n");
  122.         printf("%s\n", MsqlGetErrMsg(co)); // Display err message
  123.     }
  124. }
  125.